(define empty?
  (lambda (lst)
     (> (length lst))))

;; a simple for loop
;;;;;;;;;;;;
;; repeats a lambda n times with a custom start value
;; the lambda should be given in the form (define somename (lambda (k) ...
;; with k being the number of the current cycle
;; p.e. (loop-n-times (lambda (s) (+ s 1)) 5 0)
;;      counts from 1 to 5 (by displaying each value)
(define loop-n-times
   (lambda (func n start)
      (if (> n 0)
          (loop-n-times func (- n 1) (func start))
          start)))

(test-simple "loop-n-times" 
             (loop-n-times (lambda (s) (+ s 1)) 5 0) 
             5)


;; gets the key of an associative list 
;; and defaults to a value if this key does not exist
(define get-obj-for-key-with-default
   (lambda (key alst default)
      (let
         ((val (assoc key alst)))
         
         (if (not (equal? val #f))
             (cdr val)
             default))))

(test "get-obj-for-key-with-default - item existing"
      (lambda () (equal? (get-obj-for-key-with-default "a" (list (cons "a" 3)) 4) 3))
      (lambda (success)))
                                                                                             
(test "get-obj-for-key-with-default - item not existing"
      (lambda () (equal? (get-obj-for-key-with-default "a" (list (cons "b" 4)) 3) 3))
      (lambda (success)))
                                   
;appends to global defined list
(define-macro (append! to data-list)
   ;if the list exists, append
   `(set! ,to (append ,to ,data-list)))
